package com.gis.aoitest.source;

import ru.yandex.clickhouse.ClickHouseConnection;
import ru.yandex.clickhouse.ClickHouseDataSource;
import ru.yandex.clickhouse.ClickHouseStatement;
import ru.yandex.clickhouse.settings.ClickHouseProperties;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

public class SourceTest05_ClickHouse01 {
    public static void main(String[] args) throws SQLException {

        String url = "jdbc:clickhouse://localhost:8123/leon";
        ClickHouseProperties cp = new ClickHouseProperties();
        cp.setUser("default");
        cp.setPassword("password123");
        ClickHouseDataSource data = new ClickHouseDataSource(url,cp);

        ClickHouseConnection conn = data.getConnection();
        ClickHouseStatement stmt = conn.createStatement();
        String sql = "select * from test";
        ResultSet rs = stmt.executeQuery(sql);
        while(rs.next()){
            int id = rs.getInt(1);
            String name = rs.getString(2);
            System.out.println(id + ":" + name);
        }
    }
}
